from pyecharts.globals import CurrentConfig
from django.shortcuts import render
from django.http import HttpResponse
from .models import *
from .data_visual.tq_plot import *
CurrentConfig.ONLINE_HOST = "/static/js/assets/"


def index(request):
    # TODO 首页视图
    cits = DayData.objects.all().values_list('city')
    cits = set(map(lambda x: x[0], cits))
    return render(request, 'index.html',  {'citys': cits})


def analysis_city(request, city):
    # TODO 城市基本天气分析
    print('test')
    if city is None:
        return HttpResponse('请输入城市')
    # page = plot(city)
    page = plot(city)
    return HttpResponse(page.render_embed())
